package com.education.utils;

import com.education.welco.enums.FileTypeEnum;

import java.util.HashSet;
import java.util.Set;

import static com.education.welco.pojo.consts.FileConst.*;

/**
 * @Author: liftsail
 * @Date: 2022/9/15 13:48
 * @Description: 不积跬步无以至千里
 */
public class FileUtils {

    /**
     * 通过文件类型获取与之匹配的后缀名列表，无匹配时返回null
     *
     * @param fileType FileConst常量有声明, IMAGE_TYPE = 1, DOC_TYPE = 2 ....
     * @return
     */
    public static Set<String> getFileExtensionsByType(FileTypeEnum fileType) {

        Set<String> set = new HashSet<>();
        switch (fileType) {
            case IMAGE:
                set = IMG_FILE;
                break;
            case DOC:
                set = DOC_FILE;
                break;
            case VIDEO:
                set = VIDEO_FILE;
                break;
            case MUSIC:
                set = MUSIC_FILE;
                break;
            case APP:
                set = APP_FILE;
                break;
            case OTHER:
                set.addAll(IMG_FILE);
                set.addAll(DOC_FILE);
                set.addAll(VIDEO_FILE);
                set.addAll(MUSIC_FILE);
                set.addAll(APP_FILE);
                break;
            case ALL:
                set.addAll(IMG_FILE);
                set.addAll(DOC_FILE);
                set.addAll(VIDEO_FILE);
                set.addAll(MUSIC_FILE);
                set.addAll(APP_FILE);
                break;
            default:
                break;
        }
        return set;
    }
}
